<template>
  <div>
    <div class="form_wrap">
      <el-form label-width="120px" style="margin-top:10px">
        <!--end 法院-->
        <div class=" wrap clearfix">
          <div class="title">
            法院信息:
            <div class="button">
              <el-button @click="openDiaFy" v-if="showCourtBtn">{{
                cwTitle
              }}</el-button>
            </div>
          </div>
          <div>
            <div class="li_wrap">
              <el-form-item label="法院打款时间:">
                <el-date-picker
                  v-model="fy.agencyBeginTime"
                  type="date"
                  placeholder="选择日期时间"
                  align="right"
                  :disabled="true"
                  :picker-options="pickerOptions"
                >
                </el-date-picker>
              </el-form-item>
            </div>
            <div class="li_wrap">
              <el-form-item label="法院交接资料:">
                <el-select disabled v-model="fy.justSure">
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </div>
            <div class="li_wrap">
              <el-form-item label="领取裁定书时间:">
                <el-date-picker
                  v-model="fy.agencyEndTime"
                  type="date"
                  placeholder="选择日期时间"
                  align="right"
                  :disabled="true"
                  :picker-options="pickerOptions"
                >
                </el-date-picker>
              </el-form-item>
            </div>
          </div>
        </div>
        <!--end 权证-->
        <div class=" wrap clearfix">
          <div class="title">
            权证信息:
            <div class="button">
              <el-button @click="openDiaQz" v-if="showWarrantBtn">{{
                qzTitle
              }}</el-button>
            </div>
          </div>
          <div>
            <div class="li_wrap">
              <el-form-item label="解封时间:">
                <el-date-picker
                  v-model="qz.decompressionTime"
                  type="date"
                  placeholder="选择日期时间"
                  align="right"
                  :disabled="true"
                  :picker-options="pickerOptions"
                >
                </el-date-picker>
              </el-form-item>
            </div>
            <div class="li_wrap">
              <el-form-item label="抵押时间:">
                <el-date-picker
                  v-model="qz.pledgeTime"
                  type="date"
                  placeholder="选择日期时间"
                  align="right"
                  :disabled="true"
                  :picker-options="pickerOptions"
                >
                </el-date-picker>
              </el-form-item>
            </div>
            <div class="li_wrap">
              <el-form-item label="过户时间:">
                <el-date-picker
                  v-model="qz.transferTime"
                  type="date"
                  placeholder="选择日期时间"
                  align="right"
                  :disabled="true"
                  :picker-options="pickerOptions"
                >
                </el-date-picker>
              </el-form-item>
            </div>
            <div class="li_wrap">
              <el-form-item label="回证银行时间:">
                <el-date-picker
                  v-model="qz.obtainTime"
                  type="date"
                  placeholder="选择日期时间"
                  align="right"
                  :disabled="true"
                  :picker-options="pickerOptions"
                >
                </el-date-picker>
              </el-form-item>
            </div>
          </div>
        </div>
        <!--end 财务-->
        <div class="wrap clearfix">
          <div class="title">
            财务信息:
            <div class="button">
              <el-button @click="openDiaCw" v-if="showChargeBtn">{{
                cwTitle
              }}</el-button>
            </div>
          </div>
          <div>
            <div class="li_wrap">
              <el-form-item class="posInput ts" label="收费金额:">
                <el-input v-model="cw.chargeMoney" :disabled="true"></el-input>
                <span class="pos right">（元）</span>
              </el-form-item>
            </div>
            <div class="li_wrap">
              <el-form-item label="实际收费时间:">
                <el-date-picker
                  v-model="cw.chargeTime"
                  type="date"
                  placeholder="选择日期时间"
                  align="right"
                  :disabled="true"
                >
                </el-date-picker>
              </el-form-item>
            </div>
          </div>
        </div>
      </el-form>
    </div>
    <!--弹框-->
    <el-dialog
      title="修改信息"
      :visible.sync="dialogTableVisible"
      v-if="dialogTableVisible"
    >
      <!--end 法院-->
      <el-form label-width="150px" v-if="showdis == 1" :model="diaFy">
        <el-row>
          <el-col :span="12">
            <el-form-item label="法院打款时间:">
              <el-date-picker
                v-model="diaFy.agencyBeginTime"
                type="date"
                placeholder="选择日期时间"
                align="right"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法院交接资料:">
              <el-select v-model="diaFy.justSure">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="领取裁定书时间:">
              <el-date-picker
                v-model="diaFy.agencyEndTime"
                type="date"
                placeholder="选择日期时间"
                align="right"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="dialog-footer">
          <el-button @click="dialogTableVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitFy">确 定</el-button>
        </div>
      </el-form>
      <!--end 权证-->
      <el-form label-width="150px" v-if="showdis == 2" :model="diaQz">
        <el-row>
          <el-col :span="12">
            <el-form-item label="解封时间:">
              <el-date-picker
                v-model="diaQz.decompressionTime"
                type="date"
                placeholder="选择日期时间"
                align="right"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="抵押时间:">
              <el-date-picker
                v-model="diaQz.pledgeTime"
                type="date"
                placeholder="选择日期时间"
                align="right"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="过户时间:">
              <el-date-picker
                v-model="diaQz.transferTime"
                type="date"
                placeholder="选择日期时间"
                align="right"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="回证银行时间:">
              <el-date-picker
                v-model="diaQz.obtainTime"
                type="date"
                placeholder="选择日期时间"
                align="right"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="dialog-footer">
          <el-button @click="dialogTableVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitQz">确 定</el-button>
        </div>
      </el-form>
      <!--end 财务-->
      <el-form label-width="150px" v-if="showdis == 3" :model="diaCw">
        <el-row>
          <el-col :span="12">
            <el-form-item class="posInput ts" label="收费金额:">
              <el-input v-model="diaCw.chargeMoney"></el-input>
              <span class="pos right">（元）</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际收费时间:">
              <el-date-picker
                v-model="diaCw.chargeTime"
                type="date"
                placeholder="选择日期时间"
                align="right"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="dialog-footer">
          <el-button @click="dialogTableVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitCw">确 定</el-button>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  getProductUrl,
  getAucMort,
  putAucCourt,
  putAucWar,
  putAucCharg
} from "../../../src/assets/js/api";
import { checkPermiss } from "../../assets/js/utlis";
import { GMTToStr } from "../../assets/js/utlis";
export default {
  name: "LoanInRele",
  props: ["orderNumber"],
  data() {
    return {
      dialogTableVisible: false,
      //法院
      fy: {},
      diaFy: {},
      //权证
      qz: {},
      diaQz: {},
      //财务
      cw: {},
      diaCw: {},
      options: [
        { value: "是", label: "是" },
        { value: "否", label: "否" }
      ],
      fyTitle: "修改",
      qzTitle: "修改",
      cwTitle: "修改",
      showdis: null,
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            }
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            }
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            }
          }
        ]
      },
      golbalPermissions: [],
      ProductUrl: "",
      orderStatus: ""
    };
  },
  created() {
    this.golbalPermissions = localStorage.getItem("permissions").split(",");
    this.status = eval(this.$route.query.status);
    if (!this.status) {
      this.getUpForm(this.orderNumber);
    }
    this.findProductUrl(this.orderNumber);
  },
  computed: {
    //法院信息添加按钮
    showCourtBtn: function() {
      return checkPermiss("business:auction:court", this.golbalPermissions);
    },
    //权证信息添加按钮
    showWarrantBtn: function() {
      return checkPermiss("business:auction:warrant", this.golbalPermissions);
    },
    //财务信息添加按钮
    showChargeBtn: function() {
      return checkPermiss("business:auction:change", this.golbalPermissions);
    }
  },
  watch: {
    "fy.agencyBeginTime": {
      handler(newName) {
        if (!newName) {
          this.fyTitle = "添加数据";
        } else {
          this.fyTitle = "修改";
        }
      }
    },
    "qz.decompressionTime": {
      handler(newName) {
        if (!newName) {
          this.qzTitle = "添加数据";
        } else {
          this.qzTitle = "修改";
        }
      }
    },
    "cw.chargeMoney": {
      handler(newName) {
        if (!newName) {
          this.cwTitle = "添加数据";
        } else {
          this.cwTitle = "修改";
        }
      }
    }
  },
  methods: {
    //根据订单查询路由path路径
    findProductUrl(orderNumber) {
      getProductUrl({
        orderNumber: orderNumber
      }).then(res => {
        this.ProductUrl = res.data.productUrl;
        this.orderStatus = res.data.orderStatus;
      });
    },
    //根据订单号查询当前信息
    getUpForm(orderNumber) {
      getAucMort(orderNumber).then(res => {
        let data = res.data;
        //法院
        this.$set(this.fy, "agencyBeginTime", data.agencyBeginTime);
        this.$set(this.fy, "justSure", data.justSure);
        this.$set(this.fy, "agencyEndTime", data.agencyEndTime);
        //权证
        this.$set(this.qz, "decompressionTime", data.decompressionTime);
        this.$set(this.qz, "pledgeTime", data.pledgeTime);
        this.$set(this.qz, "transferTime", data.transferTime);
        this.$set(this.qz, "obtainTime", data.obtainTime);
        //财务
        this.$set(this.cw, "chargeMoney", data.chargeMoney);
        this.$set(this.cw, "chargeTime", data.chargeTime);
      });
    },
    //法院
    openDiaFy() {
      this.showdis = 1;
      this.dialogTableVisible = true;
      this.diaFy = JSON.parse(JSON.stringify(this.fy));
    },
    //法院信息提交按钮
    submitFy() {
      this.diaFy.orderNumber = this.orderNumber;
      if (this.diaFy.agencyBeginTime) {
        this.diaFy.agencyBeginTime = GMTToStr(this.diaFy.agencyBeginTime);
      }
      if (this.diaFy.agencyEndTime) {
        this.diaFy.agencyEndTime = GMTToStr(this.diaFy.agencyEndTime);
      }
      putAucCourt(this.diaFy).then(res => {
        if (res.code == 200) {
          this.getUpForm(this.orderNumber);
          this.dialogTableVisible = false;
          this.$message.success(res.message);
        }
      });
    },
    //权证
    openDiaQz() {
      this.showdis = 2;
      this.dialogTableVisible = true;
      this.diaQz = JSON.parse(JSON.stringify(this.qz));
    },
    //权证信息提交按钮
    submitQz() {
      this.diaQz.orderNumber = this.orderNumber;
      if (this.diaQz.decompressionTime) {
        this.diaQz.decompressionTime = GMTToStr(this.diaQz.decompressionTime);
      }
      if (this.diaQz.pledgeTime) {
        this.diaQz.pledgeTime = GMTToStr(this.diaQz.pledgeTime);
      }
      if (this.diaQz.transferTime) {
        this.diaQz.transferTime = GMTToStr(this.diaQz.transferTime);
      }
      if (this.diaQz.obtainTime) {
        this.diaQz.obtainTime = GMTToStr(this.diaQz.obtainTime);
      }
      putAucWar(this.diaQz).then(res => {
        if (res.code == 200) {
          this.getUpForm(this.orderNumber);
          this.dialogTableVisible = false;
          this.$message.success(res.message);
        }
      });
    },
    //财务
    openDiaCw() {
      this.showdis = 3;
      this.dialogTableVisible = true;
      this.diaCw = JSON.parse(JSON.stringify(this.cw));
    },
    //财务信息提交按钮
    submitCw() {
      this.diaCw.orderNumber = this.orderNumber;
      if (this.diaCw.chargeTime) {
        this.diaCw.chargeTime = GMTToStr(this.diaCw.chargeTime);
      }
      putAucCharg(this.diaCw).then(res => {
        if (res.code == 200) {
          this.getUpForm(this.orderNumber);
          this.dialogTableVisible = false;
          this.$message.success(res.message);
        }
      });
    }
  }
};
</script>

<style scoped type="less">
.posInput {
  position: relative;
}
.pos {
  position: absolute;
  z-index: 2;
}
.pos.left {
  left: 10px;
}
.pos.right {
  right: 0;
}
.posInput ::v-deep .el-input__inner {
  padding: 0 50px 0 40px;
  text-align: center;
}
.posInput.ts ::v-deep .el-input__inner {
  padding-left: 25px;
}
.toBe {
  line-height: 35px;
}
.form_wrap ::v-deep .el-form-item,
.form_wrap ::v-deep .el-form-item__label,
.form_wrap ::v-deep .el-form-item__content,
.form_wrap ::v-deep .el-input,
.form_wrap ::v-deep .el-input__inner {
  height: 32px;
  line-height: 32px;
}
.form_wrap ::v-deep .el-form-item {
  margin-bottom: 5px;
}
.form_wrap ::v-deep .el-col {
  line-height: 32px;
}
.form_wrap ::v-deep .el-button {
  padding: 8px 20px;
}
.form_wrap ::v-deep.el-input__icon {
  line-height: 24px;
}
::v-deep .el-form-item__content {
  text-align: left;
}
.el-date-editor.el-input {
  width: auto;
}
.li_wrap {
  width: 25%;
  float: left;
}
.li_wrap ::v-deep.el-select,
.li_wrap ::v-deep.el-date-editor {
  width: 100%;
}
.form_wrap .wrap {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(238, 238, 238, 1);
  border-radius: 8px;
  padding: 5px 10px;
  margin-bottom: 5px;
}
.form_wrap .title {
  text-align: left;
  font-size: 15px;
  font-family: Microsoft YaHei;
  font-weight: bold;
  color: rgba(51, 51, 51, 1);
  line-height: 40px;
}
.form_wrap .button {
  float: right;
}
</style>
